package cn.edu.njuit.springbootfilmreview.service.impl;

import cn.edu.njuit.springbootfilmreview.dto.AccountInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.njuit.springbootfilmreview.dto.MovieInfo;
import cn.edu.njuit.springbootfilmreview.service.MovieInfoService;
import cn.edu.njuit.springbootfilmreview.mapper.MovieInfoMapper;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【movie_info(影片信息)】的数据库操作Service实现
 * @createDate 2022-05-23 19:35:25
 */
@Service
public class MovieInfoServiceImpl extends ServiceImpl<MovieInfoMapper, MovieInfo> implements MovieInfoService {

    @Autowired
    MovieInfoMapper mapper;

    @Override
    public List<MovieInfo> getAllMovieInfo() {
        return mapper.selectList(null);
    }

    @Override
    public List<MovieInfo> getMovieInfoByActorName(String name) {
        return mapper.getMovieInfoByActorName(name);
    }

    @Override
    public IPage<MovieInfo> getPageAllMovieInfo(Integer currentPage, int pageSize) {

        IPage page = new Page(currentPage, pageSize);
        mapper.selectPage(page, null);
        return page;
    }

    @Override
    public IPage<MovieInfo> getPageMovieInfoByActorName(Integer currentPage, int pageSize, String actorName) {
        IPage page = new Page(currentPage, pageSize);
        mapper.getPageMovieInfoByActorName(page, actorName);
        return page;
    }

    @Override
    public IPage<MovieInfo> getPageMovieInfoByName(Integer currentPage, int pageSize, String movieName) {
        LambdaQueryWrapper<MovieInfo> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(movieName), MovieInfo::getName, movieName);
        IPage page = new Page(currentPage, pageSize);
        mapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public IPage<MovieInfo> getPageMovieInfoByMoviePublishDate(Integer currentPage, int pageSize, String moviePublishDate) {
        LambdaQueryWrapper<MovieInfo> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(moviePublishDate), MovieInfo::getMoviePublishDate, moviePublishDate);
        IPage page = new Page(currentPage, pageSize);
        mapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public IPage<MovieInfo> getPageMovieInfoByMovieYear(Integer currentPage, int pageSize, Integer movieYear) {
        LambdaQueryWrapper<MovieInfo> lqw = new LambdaQueryWrapper<>();
        lqw.like(MovieInfo::getMovieYear, movieYear);
        IPage page = new Page(currentPage, pageSize);
        mapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public IPage<MovieInfo> getPageMovieInfoByRating(Integer currentPage, int pageSize) {
        LambdaQueryWrapper<MovieInfo> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(MovieInfo::getRating);
        IPage page = new Page(currentPage, pageSize);
        mapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public MovieInfo getMovieInfoByMovieId(Long movieId) {
        return mapper.selectOne(new LambdaQueryWrapper<MovieInfo>()
                .eq(MovieInfo::getMovieId, movieId));
    }

    @Override
    public IPage<MovieInfo> getPageMovieInfoByMovieType(Integer currentPage, int pageSize, String movieType) {
        IPage page = new Page(currentPage, pageSize);
        mapper.getPageMovieInfoByMovieType(page, movieType);
        return page;
    }

    @Override
    public IPage<MovieInfo> getMovieInfoByMovieTypeAndMovieYear(Integer currentPage, int pageSize, String movieType, Integer movieYear) {
        IPage page = new Page(currentPage, pageSize);
        mapper.getMovieInfoByMovieTypeAndMovieYear(page, movieType, movieYear);
        return page;
    }

    @Override
    public IPage<MovieInfo> getMovieInfoByMovieTypeAndMovieYearAndKeyWords(Integer currentPage, int pageSize, String movieType, Integer movieYear, String movieName) {
        IPage page = new Page(currentPage, pageSize);
        mapper.getMovieInfoByMovieTypeAndMovieYearAndKeyWords(page, movieType, movieYear,movieName);
        return page;
    }

}
